{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<bound method NDFrame.tail of           0\n",
      "0   2833454\n",
      "1   2837046\n",
      "2   2835670\n",
      "3    300667\n",
      "4   1512000\n",
      "5   1600547\n",
      "6   1512200\n",
      "7   1517520\n",
      "8   1512010\n",
      "9    301353\n",
      "10   300994\n",
      "11      901\n",
      "12  1600052\n",
      "13     2937\n",
      "14  1603679\n",
      "15  1512880\n",
      "16   300067\n",
      "17   301395\n",
      "18   301106\n",
      "19   300638\n",
      "20     2889\n",
      "21      636\n",
      "22     2338\n",
      "23   301308\n",
      "24  1512480\n",
      "25  1512760\n",
      "26       37\n",
      "27      400\n",
      "28  1688100\n",
      "29  1600268\n",
      "30   159934\n",
      "31      537\n",
      "32   300433\n",
      "33  1603507\n",
      "34     2249\n",
      "35       63\n",
      "36  1601126\n",
      "37  1600064\n",
      "38  1601928>\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 读取文本文件\n",
    "file_path = 'E:\\自选股.EBK'  # 替换为你的文件路径\n",
    "# data = pd.read_csv(file_path, delimiter='\\t', header=None, names=['Date', 'Value'])\n",
    "data = pd.read_csv(file_path, delimiter='\\t', header=None)\n",
    "# 将 'Date' 列转换为日期格式\n",
    "# data['Date'] = pd.to_datetime(data['Date'])\n",
    "\n",
    "# 打印 DataFrame\n",
    "print(data.tail)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['2833454', '2837046', '2835670', '0300667', '1512000', '1600547', '1512200', '1517520', '1512010', '0301353', '0300994', '0000901', '1600052', '0002937', '1603679', '1512880', '0300067', '0301395', '0301106', '0300638', '0002889', '0000636', '0002338', '0301308', '1512480', '1512760', '0000037', '0000400', '1688100', '1600268', '0159934', '0000537', '0300433', '1603507', '0002249', '0000063', '1601126', '1600064', '1601928']\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# 读取文本文件\n",
    "file_path = 'E:\\\\自选股.EBK'  # 替换为你的文件路径\n",
    "data = pd.read_csv(file_path, delimiter='\\t', header=None, dtype=str)\n",
    "\n",
    "# 将DataFrame转换为字符串列表\n",
    "string_list = data.iloc[:, 0].tolist()\n",
    "\n",
    "print(string_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           Date   Value\n",
      "8170 2024-06-26 -1580.0\n"
     ]
    }
   ],
   "source": [
    "def read_and_convert_txt_to_dataframe(file_path):\n",
    "    \"\"\"\n",
    "    读取文本文件并将其转换为 DataFrame，同时将 'Date' 列转换为日期格式。\n",
    "\n",
    "    参数:\n",
    "    file_path (str): 文本文件的路径。\n",
    "\n",
    "    返回:\n",
    "    pd.DataFrame: 转换后的 DataFrame。\n",
    "    \"\"\"\n",
    "    # 读取文本文件\n",
    "    data = pd.read_csv(file_path, delimiter='\\t', header=None, names=['Date', 'Value'])\n",
    "    \n",
    "    # 将 'Date' 列转换为日期格式\n",
    "    data['Date'] = pd.to_datetime(data['Date'])\n",
    "    \n",
    "    return data\n",
    "\n",
    "# 示例调用\n",
    "file_path = 'M5M60.txt'  # 确保文件在当前工作目录中\n",
    "df = read_and_convert_txt_to_dataframe(file_path)\n",
    "print(df.tail(1))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
